<template>
  <!--   处置弹窗  -->
  <el-dialog
    class="dia-style"
    title="处置"
    :visible.sync="open"
    width="60%"
    :close-on-click-modal="false"
    @close="cancel">
    <HkForm
      ref="hkFormRef"
      label-width="140"
      :form-labels="formObj.formLabels"
      :rules="formObj.formRules"
      :data="formData"
      :dict-list="formObj.dictList"
      :btn-hidden="true" />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">处 置</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import HkForm from '@/components/Hk-Form'
import { dictList, disposal } from '@/api/dispose/incidentHandling'

export default {
  components: { HkForm },
  props: {},
  data() {
    return {
      open: false,
      formObj: {
        formLabels: [
          { label: '事件成因', field: 'eventCause', type: 'select', list: 'eventCauseList', span: 24 },
          { label: '危害程度评估', field: 'hazardAssess', type: 'radio', list: 'hazardAssessList', span: 24 },
          {
            label: '事件过程',
            field: 'eventProcess',
            type: 'textarea',
            span: 24,
            attrs: {
              rows: 5,
              placeholder:
                '需要详细描述事件违规详情，包括违规场景、违规过程、违规原因等。如“使用人张三在责任人李四的名称为“测试1”，ip地址为“1.1.1.1”的涉密计算机执行了“违规插拔普通存储介质”操作。',
            },
          },
          {
            label: '处置措施',
            field: 'disposalContent',
            type: 'textarea',
            span: 24,
            attrs: {
              rows: 5,
              placeholder:
                '主要描述事件的技术或管理整改措施，如“用户本地安装非授权软件”事件，技术整改措施是“卸载相关软件，配置了**产品的进程监控策略，技术上配置了**程序黑名单，管理上设置了**白名单，同时开启了**终端软件操作审计策略”',
            },
          },
        ],
        formRules: {
          eventCause: [{ required: true, message: '请选择', trigger: 'blur' }],
          hazardAssess: [{ required: true, message: '请选择', trigger: 'blur' }],
          eventProcess: [{ required: true, message: '请选择', trigger: 'blur' }],
          disposalContent: [{ required: true, message: '请选择', trigger: 'blur' }],
        },
        dictList: {
          hazardAssessList: [
            { label: '未造成失泄密', value: 0 },
            { label: '已造成失泄密', value: 1 },
          ],
          eventCauseList: [],
        },
      },
      formData: {
        hazardAssess: '1',
      },
      ids: [],
    }
  },
  created() {
    this.getDictList('incidentEventCause')
    this.getDictList('incidentHazardAssess')
  },
  methods: {
    show(ids) {
      this.open = true
      this.ids = ids
    },
    getDictList(query) {
      dictList({ itemType: query }).then((res) => {
        if (query === 'incidentEventCause') {
          //   事件成因
          this.formObj.dictList.eventCauseList = res.map((i) => {
            return { label: i.itemLabel, value: i.itemVale }
          })
        } else if (query === 'incidentHazardAssess') {
          this.formObj.dictList.hazardAssessList = res.map((i) => {
            return { label: i.itemLabel, value: i.itemVale }
          })
        }
      })
    },
    submitForm() {
      this.$refs.hkFormRef.handleFormSubmit('formLabels').then((res) => {
        disposal({ ids: this.ids, processMethod: 0, disposalStatus: 1, ...res }).then((res) => {
          this.$message.success('处置成功')
          this.$emit('handleSubmit')
          this.cancel()
        })
      })
    },
    cancel() {
      this.$refs.hkFormRef.resetForm('formLabels')

      this.open = false
    },
  },
}
</script>

<style scoped></style>
